<?php
defined('IN_PHPCMS') or exit('No permission resources.');
pc_base::load_sys_class('base');


class index extends base {
	private $db;
	function __construct() {
        pc_base::load_app_func('global');
        $siteid = isset($_GET['siteid']) ? intval($_GET['siteid']) : get_siteid();
        define("SITEID",$siteid);
        $this->db = pc_base::load_model('motoreg_model');
	}
	
	/**
	 *在线报名
	 */
	public function signup(){
		$html_title = '培训入口-在线报名';
		include template('motoreg','signup');
	}
	
	public function register() {
		if (IS_POST) {
			$data = isset($_POST['data']) ? $_POST['data'] :  showmessage(L('illegal_parameters'), HTTP_REFERER);
			$record = $this->db->get_one(array('idnumber'=>$data['idnumber']));
			if($record){
				showmessage(L('record_id_exits'));
			}else{
				$info['name'] = $data['username'];
				$info['idnumber'] = $data['idnumber'];
				$info['tel'] = $data['phone'];
				$info['site'] = SITEID;//获取当前站点
				$info['source'] = 1;//1:报名 2：参赛 用以在数据表中区分数据来源
				$info['regtime'] = time();
				$result = $this->db->insert($info);
				if ($result) {
					showmessage(L('success'),'?m=special&c=index&a=init');
				}
			}
		}
	}
	
	/**
	 *参赛观赛
	 */
	public function enjoy_game() {
		$html_title = '新丝路专题-参赛观赛报名';
		include template('spectators','enjoy_game');
	}
	
	public function enjoy_game_register(){
		if (IS_POST) {
			$enjoy = isset($_POST['enjoy']) ? $_POST['enjoy'] :  showmessage(L('illegal_parameters'), HTTP_REFERER);
			$record = $this->db->get_one(array('tel'=>$enjoy['phone'],'source'=>2));
			if($record){
				showmessage(L('record_id_exits'));
			}else{
				$info['name'] = $enjoy['username'];
				$info['email'] = $enjoy['email'];
				$info['tel'] = $enjoy['phone'];
				$info['site'] = SITEID;//获取当前站点
				$info['source'] = 2;//1:报名 2：参赛 用以在数据表中区分数据来源
				$info['regtime'] = time();
				$result = $this->db->insert($info);
				if ($result) {
					showmessage(L('success'),'?m=special&c=index&a=init');
				}
			}
		}
	}
}